<!DOCTYPE html>
<html lang="zh-CN">
  <head>
  <meta charset="UTF-8">
  <meta 
    name="viewport"
    content="width=device-width, initial-scale=1.0, minimum-scale=1.0">
  <meta 
    http-equiv="X-UA-Compatible" 
    content="ie=edge">
  <meta 
    name="theme-color" 
    content="#fff" 
    id="theme-color">
  <meta 
    name="description" 
    content="hexoDemo用于介绍如何使用hexo">
  <link 
    rel="icon" 
    href="/">
  <title>05-页面渲染性能优化</title>
  
    
      <meta 
        property="og:title" 
        content="05-页面渲染性能优化">
    
    
      <meta 
        property="og:url" 
        content="https://zwl5670.gitee.io/2014/08/01/14-%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/05-%E9%A1%B5%E9%9D%A2%E6%B8%B2%E6%9F%93%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/index.html">
    
    
      <meta 
        property="og:img" 
        content="https://img.songhn.com/img/Y67gdd.png">
    
    
      <meta 
        property="og:img" 
        content="hexoDemo用于介绍如何使用hexo">
    
    
      <meta 
        property="og:type" 
        content="article">
      <meta 
        property="og:article:published_time" 
        content="2014-08-01">
      <meta 
        property="og:article:modified_time" 
        content="2023-03-14">
      <meta 
        property="og:article:author" 
        content="zwl5670">
      
        
          <meta 
            property="og:article:tag" 
            content="性能优化">
        
      
    
  
  
  <link rel="preload" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css" as="style" >
  <link rel="preload" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css" as="style" >
  <link rel="preload" href="/css/main.css" as="style" >
  
  <link rel="modulepreload" href="//instant.page/5.1.0">
  
  <link rel="stylesheet" href="/css/main.css">
  
  <link rel="stylesheet" href="//at.alicdn.com/t/font_1946621_i1kgafibvw.css">
  
  <link rel="stylesheet" href="//at.alicdn.com/t/font_1952792_89b4ac4k4up.css">
  
  
  
    <link rel="stylesheet" href="/js/lib/lightbox/baguetteBox.min.css">
  
  <script>
    function loadScript(url, cb) {
      var script = document.createElement('script');
      script.src = url;
      if (cb) script.onload = cb;
      script.async = true;
      document.body.appendChild(script);
    }
    function loadCSS(href, data, attr) {
      var sheet = document.createElement('link');
      sheet.ref = 'stylesheet';
      sheet.href = href;
      sheet.dataset[data] = attr;
      document.head.appendChild(sheet);
    }
    function changeCSS(cssFile, data, attr) {
      var oldlink = document.querySelector(data);
      var newlink = document.createElement("link");
      newlink.setAttribute("rel", "stylesheet");
      newlink.setAttribute("href", cssFile);
      newlink.dataset.prism = attr;
      document.head.replaceChild(newlink, oldlink);
    }
  </script>
  
    
  
  <script>
    // control reverse button
    var reverseDarkList = {
      dark: 'light',
      light: 'dark'
    };
    var themeColor = {
      dark: '#1c1c1e',
      light: '#fff'
    }
    // get the data of css prefers-color-scheme
    var getCssMediaQuery = function() {
      return window.matchMedia('(prefers-color-scheme: dark)').matches ? 'dark' : 'light';
    };
    // reverse current darkmode setting function
    var reverseDarkModeSetting = function() {
      var setting = localStorage.getItem('user-color-scheme');
      if(reverseDarkList[setting]) {
        setting = reverseDarkList[setting];
      } else if(setting === null) {
        setting = reverseDarkList[getCssMediaQuery()];
      } else {
        return;
      }
      localStorage.setItem('user-color-scheme', setting);
      return setting;
    };
    // apply current darkmode setting
  </script>
  
    <script>
      var setDarkmode = function(mode) {
      var setting = mode || localStorage.getItem('user-color-scheme');
      if(setting === getCssMediaQuery()) {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[setting];
        document.getElementById('theme-color').dataset.mode = setting;
      } else if(reverseDarkList[setting]) {
        document.documentElement.setAttribute('data-user-color-scheme', setting);
        document.getElementById('theme-color').content = themeColor[setting];
        document.getElementById('theme-color').dataset.mode = setting;
      } else {
        document.documentElement.removeAttribute('data-user-color-scheme');
        localStorage.removeItem('user-color-scheme');
        document.getElementById('theme-color').content = themeColor[getCssMediaQuery()];
        document.getElementById('theme-color').dataset.mode = getCssMediaQuery();
      }
    };
    setDarkmode();
    </script>
  
  
  
    <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.js" as="script">
    <link rel="preload" href="/js/lib/lightbox/baguetteBox.min.css" as="style" >
  
  
    <link rel="preload" href="/js/lib/lozad.min.js" as="script">
  
  
  
  
  
  
<meta name="generator" content="Hexo 6.3.0"></head>

  <body>
    <div class="wrapper">
       
      <nav class="navbar">
  <div class="navbar-logo">
    <a class="navbar-logo-main" href="/">
      
      <span class="navbar-logo-dsc">前端面试</span>
      </a>
  </div>
  <div class="navbar-menu">
    
      <a 
        href="/" 
        class="navbar-menu-item">
        
          首页
        
      </a>
    
      <a 
        href="/archives" 
        class="navbar-menu-item">
        
          归档
        
      </a>
    
      <a 
        href="/tags" 
        class="navbar-menu-item">
        
          标签
        
      </a>
    
      <a 
        href="/categories" 
        class="navbar-menu-item">
        
          分类
        
      </a>
    
      <a 
        href="/about" 
        class="navbar-menu-item">
        
          关于
        
      </a>
    
      <a 
        href="/links" 
        class="navbar-menu-item">
        
          友链
        
      </a>
    
    <button 
      class="navbar-menu-item darknavbar navbar-menu-btn" 
      aria-label="Toggle dark mode"
      id="dark">
      <i class="iconfont icon-weather"></i>
    </button>
    <button 
      class="navbar-menu-item searchnavbar navbar-menu-btn" 
      aria-label="Toggle search"
      id="search">
      <!-- <i 
        class="iconfont icon-search" 
        style="font-size: 1.2rem; font-weight: 400;">
      </i> -->
      <svg xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" aria-hidden="true" role="img"
        class="iconify iconify--ion" width="28" height="28" preserveAspectRatio="xMidYMid meet" viewBox="0 0 512 512">
        <path fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="28"
          d="M256 80a176 176 0 1 0 176 176A176 176 0 0 0 256 80Z"></path>
        <path fill="none" stroke="currentColor" stroke-miterlimit="10" stroke-width="28"
          d="M232 160a72 72 0 1 0 72 72a72 72 0 0 0-72-72Z"></path>
        <path fill="none" stroke="currentColor" stroke-linecap="round" stroke-miterlimit="10" stroke-width="28"
          d="M283.64 283.64L336 336"></path>
      </svg>
    </button>
  </div>
</nav> 
      
      <div 
        id="local-search" 
        style="display: none">
        <input
          class="navbar-menu-item"
          id="search-input"
          placeholder="请输入搜索内容..." />
        <div id="search-content"></div>
      </div>
      
      <div class="section-wrap">
        <div class="container">
          <div class="columns">
            <aside class="left-column">
              
              <div class="card card-author">
                
  <img 
    src="https://img.songhn.com/img/Y67gdd.png" 
    class="author-img"
    width="88"
    height="88"
    alt="author avatar">

<p class="author-name">zwl5670</p>
<p class="author-description">前端学习资料</p>
<div class="author-message">
  <a 
    class="author-posts-count" 
    href="/archives">
    <span>215</span>
    <span>文章</span>
  </a>
  <a 
    class="author-categories-count" 
    href="/categories">
    <span>14</span>
    <span>分类</span>
  </a>
  <a 
    class="author-tags-count" 
    href="/tags">
    <span>14</span>
    <span>标签</span>
  </a>
</div>

              </div>
               <div class="sticky-tablet">
  
  
    <article class="display-when-two-columns spacer">
      <div class="card card-content toc-card">
        <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8F%E8%A7%88%E5%99%A8%E6%B8%B2%E6%9F%93%E8%BF%87%E7%A8%8B"><span class="toc-text">浏览器渲染过程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E6%B8%B2%E6%9F%93%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88%E6%80%BB%E8%A7%88"><span class="toc-text">页面渲染技术方案总览</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E5%8C%96%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">静态化技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB%E6%8A%80%E6%9C%AF%E4%B8%8E%E5%AE%9E%E7%8E%B0"><span class="toc-text">前后端分离技术与实现</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8D%95%E9%A1%B5%E9%9D%A2%E5%BA%94%E7%94%A8%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">单页面应用技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#BigPipe-%E7%AE%80%E4%BB%8B%E5%92%8C%E5%B7%A5%E4%BD%9C%E6%A8%A1%E5%BC%8F"><span class="toc-text">BigPipe 简介和工作模式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%90%8C%E6%9E%84%E7%9B%B4%E5%87%BA%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">同构直出技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PWA-%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88%E5%92%8C%E5%AE%9E%E7%8E%B0%E6%80%9D%E8%B7%AF"><span class="toc-text">PWA 技术方案和实现思路</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E7%AD%96%E7%95%A5%E4%BC%98%E5%8C%96"><span class="toc-text">页面加载策略优化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%87%92%E5%8A%A0%E8%BD%BD"><span class="toc-text">懒加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A2%84%E5%8A%A0%E8%BD%BD"><span class="toc-text">预加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A2%84%E6%B8%B2%E6%9F%93"><span class="toc-text">预渲染</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8C%89%E9%9C%80%E5%8A%A0%E8%BD%BD"><span class="toc-text">按需加载</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3%E6%9C%8D%E5%8A%A1%E8%B0%83%E7%94%A8%E4%BC%98%E5%8C%96"><span class="toc-text">接口服务调用优化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3%E7%BC%93%E5%AD%98%E7%AD%96%E7%95%A5%E4%BC%98%E5%8C%96"><span class="toc-text">接口缓存策略优化</span></a></li></ol>
      </div>
    </article>
  
  
  <article class="card card-content categories-widget">
    <div class="categories-card">
  <div class="categories-header">
    <i 
      class="iconfont icon-fenlei" 
      style="padding-right: 2px;">
    </i>分类
  </div>
  <div class="categories-list">
    
      <a href="/categories/%E5%89%8D%E7%AB%AF%E5%B7%A5%E5%85%B7/">
        <div class="categories-list-item">
          前端工具
          <span class="categories-list-item-badge">13</span>
        </div>
      </a>
    
      <a href="/categories/CSS%E5%9F%BA%E7%A1%80/">
        <div class="categories-list-item">
          CSS基础
          <span class="categories-list-item-badge">18</span>
        </div>
      </a>
    
      <a href="/categories/CSS%E8%BF%9B%E9%98%B6/">
        <div class="categories-list-item">
          CSS进阶
          <span class="categories-list-item-badge">9</span>
        </div>
      </a>
    
      <a href="/categories/HTML/">
        <div class="categories-list-item">
          HTML
          <span class="categories-list-item-badge">12</span>
        </div>
      </a>
    
      <a href="/categories/JS%E5%9F%BA%E7%A1%80/">
        <div class="categories-list-item">
          JS基础
          <span class="categories-list-item-badge">56</span>
        </div>
      </a>
    
      <a href="/categories/JS%E5%9F%BA%E7%A1%80ES6/">
        <div class="categories-list-item">
          JS基础ES6
          <span class="categories-list-item-badge">10</span>
        </div>
      </a>
    
      <a href="/categories/JS%E5%9F%BA%E7%A1%80%E5%BC%82%E6%AD%A5/">
        <div class="categories-list-item">
          JS基础异步
          <span class="categories-list-item-badge">11</span>
        </div>
      </a>
    
      <a href="/categories/JS%E8%BF%9B%E9%98%B6/">
        <div class="categories-list-item">
          JS进阶
          <span class="categories-list-item-badge">11</span>
        </div>
      </a>
    
      <a href="/categories/%E7%A7%BB%E5%8A%A8web/">
        <div class="categories-list-item">
          移动web
          <span class="categories-list-item-badge">3</span>
        </div>
      </a>
    
      <a href="/categories/CSS%E5%92%8CDOM/">
        <div class="categories-list-item">
          CSS和DOM
          <span class="categories-list-item-badge">6</span>
        </div>
      </a>
    
      <a href="/categories/Node/">
        <div class="categories-list-item">
          Node
          <span class="categories-list-item-badge">16</span>
        </div>
      </a>
    
      <a href="/categories/Vue%E5%9F%BA%E7%A1%80/">
        <div class="categories-list-item">
          Vue基础
          <span class="categories-list-item-badge">15</span>
        </div>
      </a>
    
      <a href="/categories/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/">
        <div class="categories-list-item">
          性能优化
          <span class="categories-list-item-badge">7</span>
        </div>
      </a>
    
      <a href="/categories/%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%8C%96/">
        <div class="categories-list-item">
          前端工程化
          <span class="categories-list-item-badge">8</span>
        </div>
      </a>
    
  </div>
</div>
  </article>
  
  <article class="card card-content tags-widget">
    <div class="tags-card">
  <div class="tags-header">
    <i 
      class="iconfont icon-biaoqian" 
      style="padding-right: 2px;">
    </i>热门标签
  </div>
  <div class="tags-list">
    
      <a 
        href="/tags/JS%E5%9F%BA%E7%A1%80/" 
        title="JS基础">
        <div class="tags-list-item">JS基础</div>
      </a>
    
      <a 
        href="/tags/CSS%E5%9F%BA%E7%A1%80/" 
        title="CSS基础">
        <div class="tags-list-item">CSS基础</div>
      </a>
    
      <a 
        href="/tags/Node/" 
        title="Node">
        <div class="tags-list-item">Node</div>
      </a>
    
      <a 
        href="/tags/Vue%E5%9F%BA%E7%A1%80/" 
        title="Vue基础">
        <div class="tags-list-item">Vue基础</div>
      </a>
    
      <a 
        href="/tags/%E5%89%8D%E7%AB%AF%E5%B7%A5%E5%85%B7/" 
        title="前端工具">
        <div class="tags-list-item">前端工具</div>
      </a>
    
      <a 
        href="/tags/HTML/" 
        title="HTML">
        <div class="tags-list-item">HTML</div>
      </a>
    
      <a 
        href="/tags/JS%E8%BF%9B%E9%98%B6/" 
        title="JS进阶">
        <div class="tags-list-item">JS进阶</div>
      </a>
    
      <a 
        href="/tags/JS%E5%9F%BA%E7%A1%80%E5%BC%82%E6%AD%A5/" 
        title="JS基础异步">
        <div class="tags-list-item">JS基础异步</div>
      </a>
    
      <a 
        href="/tags/JS%E5%9F%BA%E7%A1%80ES6/" 
        title="JS基础ES6">
        <div class="tags-list-item">JS基础ES6</div>
      </a>
    
      <a 
        href="/tags/CSS%E8%BF%9B%E9%98%B6/" 
        title="CSS进阶">
        <div class="tags-list-item">CSS进阶</div>
      </a>
    
      <a 
        href="/tags/%E5%89%8D%E7%AB%AF%E5%B7%A5%E7%A8%8B%E5%8C%96/" 
        title="前端工程化">
        <div class="tags-list-item">前端工程化</div>
      </a>
    
      <a 
        href="/tags/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/" 
        title="性能优化">
        <div class="tags-list-item">性能优化</div>
      </a>
    
      <a 
        href="/tags/CSS%E5%92%8CDOM/" 
        title="CSS和DOM">
        <div class="tags-list-item">CSS和DOM</div>
      </a>
    
      <a 
        href="/tags/%E7%A7%BB%E5%8A%A8web/" 
        title="移动web">
        <div class="tags-list-item">移动web</div>
      </a>
    
  </div>
</div>
  </article>
  
  
</div>
            </aside>
            <main class="main-column">
              
<article class="card card-content">
  <header>
    <h1 class="post-title">
      05-页面渲染性能优化
    </h1>
  </header>
  <div class="post-meta post-show-meta">
    <time datetime="2014-07-31T16:00:00.000Z">
      <i 
        class="iconfont icon-calendar" 
        style="margin-right: 2px;">
      </i>
      <span>2014-08-01</span>
    </time>
    
      <span class="dot"></span>
      
        <a 
          href="/categories/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/" 
          class="post-meta-link">
          性能优化
        </a>
      
    
    
      <span class="dot"></span>
      <span>3.3k 字</span>
    
  </div>
  
    <div 
      class="post-meta post-show-meta" 
      style="margin-top: -10px;">
      <div style="display: flex; align-items: center;">
        <i 
          class="iconfont icon-biaoqian" 
          style="margin-right: 2px; font-size: 1.15rem;">
        </i>
        
          
          <a 
            href="/tags/%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/" 
            class="post-meta-link">
            性能优化
          </a>
        
      </div>
    </div>
  
  </header>
  <div 
    id="section" 
    class="post-content">
    <p><ArticleTopAd></ArticleTopAd></p>
<h2 id="浏览器渲染过程"><a href="#浏览器渲染过程" class="headerlink" title="浏览器渲染过程"></a>浏览器渲染过程</h2><p><img  srcset="data:image/svg+xml,%3Csvg%20xmlns='http://www.w3.org/2000/svg'%20viewBox='0%200%20300%20300'%3E%3C/svg%3E" data-src="https://img.smyhvae.com/20210114_2115.png" class="lozad post-image"src="https://img.smyhvae.com/20210114_2115.png"></p>
<ol>
<li><p>浏览器解析 HTML，生成 DOM Tree（Parse HTML）。</p>
</li>
<li><p>浏览器解析 CSS，生成 CSSOM（CSS Object Model）Tree。</p>
</li>
<li><p>JavaScript 会通过 DOM API 和 CSSOM API 来操作 DOM Tree 和 CSS Rule Tree，浏览器将 DOM Tree 和 CSSOM Tree 合成渲染树（Render Tree）。</p>
</li>
<li><p>布局（Layout）：根据生成的 Render Tree，进行回流，以计算每个节点的几何信息（位置、大小、字体样式等等）。</p>
</li>
<li><p>绘制（Painting）：根据渲染树和回流得到的几何信息，得到每个节点的绝对像素。</p>
</li>
<li><p>展示（Display）：将像素发送给图形处理器（GPU），展示在页面上。</p>
</li>
</ol>
<h2 id="页面渲染技术方案总览"><a href="#页面渲染技术方案总览" class="headerlink" title="页面渲染技术方案总览"></a>页面渲染技术方案总览</h2><p><strong>服务端渲染</strong>：</p>
<ul>
<li>后端同步渲染、同构直出、BigPipe。</li>
</ul>
<p><strong>客户端渲染</strong>：</p>
<ul>
<li><p>JavaScript 渲染：静态化、前后端分离、单页面应用</p>
</li>
<li><p>Web App：React、Vue、PWA</p>
</li>
<li><p>Hybrid App：PhoneGap 、AppCan 等</p>
</li>
<li><p>跨平台开发：RN 、Flutter 、小程序等。</p>
</li>
<li><p>原生 App：iOS 、Android</p>
</li>
</ul>
<p>建议：</p>
<ul>
<li>依赖业务形式、依赖团队规模、依赖技术水平。</li>
</ul>
<h2 id="静态化技术方案"><a href="#静态化技术方案" class="headerlink" title="静态化技术方案"></a>静态化技术方案</h2><p>静态化是使动态化的网站生成静态 HTML 页面以供用户更好访问的技术，一般分为纯动态化和伪动态化。</p>
<p>技术优势：</p>
<ul>
<li><p>提高了页面访问速度，降低了服务器的负担，因为访问页面时不需要每次去访问数据库。</p>
</li>
<li><p>提高网站内容被搜索引擎搜索到的几率，因为搜索引擎更喜欢静态页面。</p>
</li>
<li><p>网站更稳定，如果后端程序、数据库出现问题，会直接影响网站的正常访问，而静态化页面有缓存，更不容易出现问题。</p>
</li>
</ul>
<p>技术不足：</p>
<ul>
<li><p>服务器存储占用问题，因为页面量级在增加，要占用大量硬盘空间。</p>
</li>
<li><p>静态页面中的链接更新问题会有死链或者错误链接问题。</p>
</li>
</ul>
<p>技术实现：</p>
<ul>
<li><p>跑定时任务，将已有的动态内容进行重定，生成静态的 HTML 页面。</p>
</li>
<li><p>利用模板技术，将模板引擎中模板字符替换为从数据库字段中取出来的值， 同时生成 HTML 文件。</p>
</li>
</ul>
<p>协作方式：</p>
<ul>
<li><p>前端统一写好带有交互的完整静态页面。</p>
</li>
<li><p>后端拆分出静态页面文件，并嵌套在后端模板文件中。</p>
</li>
</ul>
<p>选型建议：后端研发人员充分，又需要考虑用户体验、服务器负载的业务。</p>
<h2 id="前后端分离技术与实现"><a href="#前后端分离技术与实现" class="headerlink" title="前后端分离技术与实现"></a>前后端分离技术与实现</h2><p>前后端分离是指研发人员分离、业务代码分离、后端实现业务接口，前端渲染页面。</p>
<p>技术实现：</p>
<ul>
<li><p>后端只负责功能接口实现，提供按照约定的数据格式并封装好的 API 接口。</p>
</li>
<li><p>前端负责业务具体实现，获取到 API 接口数据后，进行页面模板拼接和渲染，独立上线。</p>
</li>
</ul>
<p>协作方式：</p>
<ul>
<li><p>前端负责实现页面前端交互，根据后端 API 接口拼装前端模板。</p>
</li>
<li><p>后端专注于业务功能实现和 API 接口封装。</p>
</li>
</ul>
<p>技术优势：</p>
<ul>
<li><p>团队更加专注</p>
</li>
<li><p>提升了开发效率</p>
</li>
<li><p>增加代码可维护性</p>
</li>
</ul>
<p>技术架构：</p>
<ul>
<li><p>后端架构：Java、C++、PHP、 + Nginx，使用微服务（比如 Dubbo 等）等实现业务的解耦，所有的服务使用某种协议提供不同的服务（比如 JSF 等） 。</p>
</li>
<li><p>前端架构：使用 Angular、React、Vue 前端框架并部署页面至 CDN。</p>
</li>
<li><p>前端架构 2：使用 Angular、React、Vue 前端框架并部署在 Node Server。</p>
</li>
</ul>
<p>技术不足：</p>
<ul>
<li><p>因为前端需要负责一大部分业务逻辑实现，和服务端同步、静态化，需要前端人力非常多。</p>
</li>
<li><p>页面数据异步渲染，不利于 SEO，搜索引擎更喜欢纯静态页面。</p>
</li>
</ul>
<p>选型建议：</p>
<ul>
<li>这是大型互联网公司正在采用的开发模式，一句话，如果考虑用户体验，以及前端人力够用，就可以积极采用。</li>
</ul>
<h2 id="单页面应用技术方案"><a href="#单页面应用技术方案" class="headerlink" title="单页面应用技术方案"></a>单页面应用技术方案</h2><p>单页应用（single-page application，缩写 SPA），通过动态重写当前页面，来与用户交互，而非传统的从服务器重新加载整个新页面。这种方法在使用过程中不需要重新加载页面，避免了页面之间切换打断用户体验，使应用程序更像一个桌面应用程序。</p>
<p>技术优点：</p>
<ul>
<li><p>不错的加载速度：用户往往感觉页面加载非常快，因为一进入页面就能看到页面元素；</p>
</li>
<li><p>良好的交互体验：进行局部渲染，避免不必要的页面间跳转和重复渲染；</p>
</li>
<li><p>前后端职责分离：前端进行页面交互逻辑，后端负责业务逻辑；</p>
</li>
<li><p>减轻服务器负载：服务器只处理数据接口输出，不用考虑页面模板渲染和 HTML 展示。</p>
</li>
</ul>
<p>技术缺点：</p>
<ul>
<li><p>开发成本相对较高</p>
</li>
<li><p>首次页面加载时间过多</p>
</li>
<li><p>SEO 难度比较大</p>
</li>
</ul>
<p>技术实现：</p>
<ul>
<li>使用 React、Vue 框架可以很好的。</li>
</ul>
<h2 id="BigPipe-简介和工作模式"><a href="#BigPipe-简介和工作模式" class="headerlink" title="BigPipe 简介和工作模式"></a>BigPipe 简介和工作模式</h2><p>BigPipe 通过将页面加载到称为 Pagelet 的小部件中，来加快页面渲染速度，并允许浏览器在 PHB 服务器呈现页面的同时，一直请求页面不同区块的结构，类似一个“流”传输管道。</p>
<p><strong>技术实现</strong>：</p>
<ol>
<li><p>浏览器从服务器请求页面。</p>
</li>
<li><p>Server 迅速呈现一个包含 <head> 标记的页面框架，以及一个包含空 div 元素的主体，这些元素充当 Pagelet 的容器。由于该页面尚未完成，因此与浏览器的 HTTP 连接保持打开状态。</p>
</li>
<li><p>浏览器将开始下载 bigpipe.js 文件，然后它将开始呈现页面。</p>
</li>
<li><p>PHP 服务器进程仍在执行，并且一次构建每个 Pagelet 。Pagelet 完成后，其结果将在<code>&lt;script&gt; BigPipe.onArrive（…）&lt;/ script&gt;</code> 标记内发送到浏览器。</p>
</li>
<li><p>浏览器将收到的 html 代码注入正确的位置。如果小页面需要任何 CSS 资源，则也将下载这些 CSS 资源。</p>
</li>
<li><p>接收完所有的页面集之后，浏览器将开始加载那些页面集所需的所有外部 JavaScript 文件。</p>
</li>
<li><p>下载 JavaScript 后，浏览器将执行所有内联 JavaScript。</p>
</li>
</ol>
<h2 id="同构直出技术方案"><a href="#同构直出技术方案" class="headerlink" title="同构直出技术方案"></a>同构直出技术方案</h2><p>一套代码既可以在服务端运行又可以在客户端运行，这就是同构（Universal）。</p>
<p>技术优势：</p>
<ul>
<li><p>性能: 降低首屏渲染时间</p>
</li>
<li><p>SEO: 服务端渲染对搜索引擎的爬取有着天然的优势</p>
</li>
<li><p>兼容性: 有效规避客户端兼容性问题，比如白屏</p>
</li>
<li><p>代码同构：直接上线两个版本，利于灾备。</p>
</li>
</ul>
<p>技术实现：</p>
<ul>
<li><p>next.js：服务器端渲染 React 组件框架（参考查看：<a target="_blank" rel="noopener" href="https://nextjs.org/%EF%BC%89">https://nextjs.org/）</a>, React 采用 ReactDOMServer 调用 renderToString() 方法。</p>
</li>
<li><p>gatsbyjs：服务端 React 渲染框架（参考查看： <a target="_blank" rel="noopener" href="https://www.gatsbyjs.org/%EF%BC%89%E3%80%82">https://www.gatsbyjs.org/）。</a></p>
</li>
<li><p>nuxt.js：服务器端渲染 Vue 组件框架（参考查看：<a target="_blank" rel="noopener" href="https://nuxtjs.org/%EF%BC%89">https://nuxtjs.org/）</a>, Vue 采用 vue-server-renderer 调用 renderToString() 方法。</p>
</li>
</ul>
<p>协作方式：</p>
<ul>
<li><p>后端专注于业务功能实现和 API 接口封装。</p>
</li>
<li><p>前端负责实现页面前端交互，根据后端 API 接口拼装前端模板，页面渲染，以及服务器维护。</p>
</li>
</ul>
<p>选型建议：</p>
<ul>
<li><p>前端要处理 Node server 的机器环境、代码部署、日志、容灾、监控等以往后端人员需要具备运维知识，前端人员的综合能力要求会比以往要高。</p>
</li>
<li><p>前端项目开发周期变长了，需要事先和产品、运营沟通排期问题。</p>
</li>
</ul>
<h2 id="PWA-技术方案和实现思路"><a href="#PWA-技术方案和实现思路" class="headerlink" title="PWA 技术方案和实现思路"></a>PWA 技术方案和实现思路</h2><p>Progressive Web App，简称 PWA，PWA 应用是使用特定技术和标准模式来开发的 Web 应用，这将同时赋予它们 Web 应用和原生应用的特性。</p>
<p>技术优势：</p>
<ul>
<li><p>用户可以用手机屏幕启动应用，即使在离线状态或者弱网下，通过事先缓存的资源，也可正常加载运行当前应用，可以完全消除对网络的依赖，从而给用户非常可靠的体验。</p>
</li>
<li><p>因为预先缓存了资源，部分资源无须经过网络，即秒开页面。</p>
</li>
<li><p>和移动设备上的原生应用一样，具有沉浸式的用户体验。</p>
</li>
<li><p>可以给用户发送离线推送消息。</p>
</li>
</ul>
<p>技术实现：</p>
<ul>
<li><p>全站改造成 HTTPS，没有 HTTPS 就没有 Service Worker。</p>
</li>
<li><p>应用 Service Worker 技术提升性能，离线提供静态资源文件，提升首屏用户体验。</p>
</li>
<li><p>使用 App Manifest。</p>
</li>
<li><p>最后可以考虑离线消息推送等功能。</p>
</li>
</ul>
<p>浏览器兼容性：</p>
<ul>
<li><p>ServiceWorkerGlobalScope API：88%</p>
</li>
<li><p>Web App Manifest 83%</p>
</li>
</ul>
<h2 id="页面加载策略优化"><a href="#页面加载策略优化" class="headerlink" title="页面加载策略优化"></a>页面加载策略优化</h2><ul>
<li><p>懒加载</p>
</li>
<li><p>预加载</p>
</li>
<li><p>预渲染</p>
</li>
<li><p>按需加载</p>
</li>
</ul>
<p>下面具体展开讲讲。</p>
<h3 id="懒加载"><a href="#懒加载" class="headerlink" title="懒加载"></a>懒加载</h3><p>懒加载也叫延迟加载，指的是长网页中延迟加载特定元素（可以是图片，也可以是 JS&#x2F;CSS 文件，当然也可以是 JavaScript 的特定函数和方法，以下简称“懒加载元素”）。</p>
<p>好处：可以减少当前屏无效资源的加载。</p>
<p>技术实现举例：把页面上“懒加载元素”src 属性设置为空字符，把真实的 src 属性写在 data-lazy 属性中，当页面滚动的时候监听 scroll 事件，如果“懒加载元素”在可视区域内，就把图片的 src 属性或者文件 URL 路径设置成 data-lazy 属性值。</p>
<h3 id="预加载"><a href="#预加载" class="headerlink" title="预加载"></a>预加载</h3><p>可以使用预加载让浏览器来预先加载某些资源（比如图片、JS&#x2F;CSS&#x2F;模板），而这些资源是在将来才会被使用到的。简单来说，就是将所需资源提前加载到浏览器本地，这样后面在需要使用的时候就可以直接从浏览器缓存中取了，而不用再重新开始加载。</p>
<p>使用场景：如果你希望这个资源能尽快显示给用户，就可以使用预加载。</p>
<p>好处：减少用户后续加载资源等待的时间。</p>
<p><strong>技术实现举例</strong>：</p>
<ol>
<li>HTML 标签：</li>
</ol>
<pre class="highlight"><span class="line"><span class="tag">&lt;<span class="name">img</span> <span class="attr">src</span>=<span class="string">&quot;https://xxx.jpg&quot;</span> <span class="attr">style</span>=<span class="string">&quot;display: none&quot;</span> /&gt;</span></span><br></pre>

<p>2、使用 Image 对象：</p>
<pre class="highlight"><span class="line"><span class="keyword">const</span> image = <span class="keyword">new</span> <span class="title class_">Image</span>();</span><br><span class="line"></span><br><span class="line">image.<span class="property">src</span> = <span class="string">&#x27;https://xxx.jpg&#x27;</span>;</span><br></pre>

<p>3、使用 preload、prefetch 和 preconnect：</p>
<pre class="highlight"><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">“preload”</span> <span class="attr">href</span>=<span class="string">“src/style.css”</span> <span class="attr">as</span>=<span class="string">“style”</span>&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;prefetch&quot;</span> <span class="attr">href</span>=<span class="string">&quot;scr/image.png&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;dns-prefetch&quot;</span> <span class="attr">href</span>=<span class="string">&quot;https://my.com&quot;</span> /&gt;</span></span><br><span class="line"></span><br><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;preconnect&quot;</span> <span class="attr">href</span>=<span class="string">&quot;https://my.com&quot;</span> <span class="attr">crossorigin</span> /&gt;</span></span><br></pre>

<h3 id="预渲染"><a href="#预渲染" class="headerlink" title="预渲染"></a>预渲染</h3><p>有一种预加载组件的方式就是提前渲染它。在页面中渲染组件，但是并不在页面中展示。也就是渲染完成后，先隐藏起来，用的时候再展示。</p>
<p>实现举例：</p>
<pre class="highlight"><span class="line"><span class="tag">&lt;<span class="name">link</span> <span class="attr">rel</span>=<span class="string">&quot;prerender&quot;</span> <span class="attr">href</span>=<span class="string">&quot;https://my.com&quot;</span> /&gt;</span></span><br></pre>

<h3 id="按需加载"><a href="#按需加载" class="headerlink" title="按需加载"></a>按需加载</h3><ul>
<li><p>常规按需加载（如 JS 原生、jQuery）</p>
</li>
<li><p>不同 App 按需加载（如 JS-SDK 脚本文件）</p>
</li>
<li><p>不同设备按需加载（如 PC 端和 HTML5 端样式文件）</p>
</li>
<li><p>不同分辨率按需加载（CSS Media Query）</p>
</li>
</ul>
<p>React 异步加载举例：</p>
<pre class="highlight"><span class="line"><span class="keyword">const</span> <span class="title function_">componentA</span> = (<span class="params">location, callback</span>) =&gt; &#123;</span><br><span class="line">    <span class="built_in">require</span>.<span class="title function_">ensure</span>(</span><br><span class="line">        [],</span><br><span class="line">        <span class="function">(<span class="params"><span class="built_in">require</span></span>) =&gt;</span> &#123;</span><br><span class="line">            <span class="title function_">callback</span>(<span class="literal">null</span>, <span class="built_in">require</span>(<span class="string">&#x27;modules/componentA&#x27;</span>));</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&#x27;componentA&#x27;</span></span><br><span class="line">    );</span><br><span class="line">&#125;;</span><br><span class="line"><span class="keyword">const</span> <span class="title function_">componentB</span> = (<span class="params">location, callback</span>) =&gt; &#123;</span><br><span class="line">    <span class="built_in">require</span>.<span class="title function_">ensure</span>(</span><br><span class="line">        [],</span><br><span class="line">        <span class="function">(<span class="params"><span class="built_in">require</span></span>) =&gt;</span> &#123;</span><br><span class="line">            <span class="title function_">callback</span>(<span class="literal">null</span>, <span class="built_in">require</span>(<span class="string">&#x27;modules/componentB&#x27;</span>));</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="string">&#x27;componentB&#x27;</span></span><br><span class="line">    );</span><br><span class="line">&#125;;</span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">Router</span> <span class="attr">history</span>=<span class="string">&#123;history&#125;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;<span class="name">Route</span> <span class="attr">path</span>=<span class="string">&quot;/&quot;</span> <span class="attr">component</span>=<span class="string">&#123;App&#125;</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;<span class="name">Route</span> <span class="attr">path</span>=<span class="string">&quot;componentA&quot;</span> <span class="attr">getComponent</span>=<span class="string">&#123;componentA&#125;</span>&gt;</span><span class="tag">&lt;/<span class="name">Route</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">        <span class="tag">&lt;<span class="name">Route</span> <span class="attr">path</span>=<span class="string">&quot;componentB&quot;</span> <span class="attr">getComponent</span>=<span class="string">&#123;componentB&#125;</span>&gt;</span><span class="tag">&lt;/<span class="name">Route</span>&gt;</span></span></span><br><span class="line"><span class="language-xml">    <span class="tag">&lt;/<span class="name">Route</span>&gt;</span></span></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;/<span class="name">Router</span>&gt;</span></span>;</span><br></pre>

<p>Vue 异步加载举例：</p>
<pre class="highlight"><span class="line"><span class="keyword">import</span> <span class="title class_">Vue</span> <span class="keyword">from</span> <span class="string">&#x27;vue&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">App</span> <span class="keyword">from</span> <span class="string">&#x27;./App.vue&#x27;</span>;</span><br><span class="line"><span class="keyword">import</span> <span class="title class_">VueRouter</span> <span class="keyword">from</span> <span class="string">&#x27;vue-router&#x27;</span>;</span><br><span class="line"></span><br><span class="line"><span class="title class_">Vue</span>.<span class="title function_">use</span>(<span class="title class_">VueRouter</span>);</span><br><span class="line"><span class="keyword">const</span> <span class="title function_">componentA</span> = resolve =&gt; <span class="built_in">require</span>([<span class="string">&#x27;src/a.vue&#x27;</span> ], resolve);</span><br><span class="line"><span class="keyword">const</span> <span class="title function_">componentB</span> = resolve =&gt; <span class="built_in">require</span>([<span class="string">&#x27;src/b.vue&#x27;</span> ], resolve);</span><br><span class="line"><span class="keyword">const</span> router = <span class="keyword">new</span> <span class="title class_">VueRouter</span>(&#123;</span><br><span class="line">    <span class="attr">routes</span>: [&#123;<span class="attr">path</span>:<span class="string">&quot;a”,name:&quot;</span>/a”,<span class="attr">component</span>:componentA&#125;,</span><br><span class="line">     &#123;<span class="attr">path</span>:<span class="string">&quot;b”,name:&quot;</span>/b”,<span class="attr">component</span>:componentB&#125;]</span><br><span class="line">&#125;)</span><br><span class="line"><span class="keyword">new</span> <span class="title class_">Vue</span>(&#123;</span><br><span class="line">    <span class="attr">el</span>: <span class="string">&#x27;#app&#x27;</span>,</span><br><span class="line">    <span class="attr">router</span>: router,</span><br><span class="line">    <span class="attr">render</span>: <span class="function"><span class="params">h</span> =&gt;</span> <span class="title function_">h</span>(<span class="title class_">App</span>)</span><br><span class="line">&#125;)</span><br></pre>

<h2 id="接口服务调用优化"><a href="#接口服务调用优化" class="headerlink" title="接口服务调用优化"></a>接口服务调用优化</h2><p>1、接口合并：一个页面的众多业务接口和依赖的第三方接口，合并为一个部署在集群的接口统一调用，以减少页面接口请求数。</p>
<p>2、接口上 CDN：主要基于接口性能考虑，我们可以把<strong>不需要实时更新的接口同步至 CDN</strong>，等此接口内容变更之后自动同步至 CDN 集群上。如果一定时间内未请求到数据，会用源站接口再次请求。</p>
<p>3、接口域名上 CDN：增强可用性、稳定性。</p>
<p>4、接口降级：核心接口进行降级用基础接口进行业务实现，比如千人千面的推荐接口，在大促时间点可以直接运营编辑的数据。另外如果接口无访问，建议使用兜底数据。</p>
<p>5、接口监控：监控接口成功率，不只是常说的 TP99，也包括弱网、超时、网络异常、网络切换等一段情况的监控情况。排查出来问题后，需要联合后端、运维、网络岗位人员一并解决。</p>
<h2 id="接口缓存策略优化"><a href="#接口缓存策略优化" class="headerlink" title="接口缓存策略优化"></a>接口缓存策略优化</h2><p>1、Ajax&#x2F;fetch 缓存：前端请求时候带上 cache，依赖浏览器本身缓存机制。</p>
<p>2、本地缓存：异步接口数据优先使用本地 localStorage 中的缓存数据。</p>
<p>3、多次请求：接口数据本地无 localStorage 缓存数据，重新再次发出 ajax 请求。</p>

  </div>
  <div>
    
      <div 
        class="post-note note-warning copyright" 
        style="margin-top: 42px">
        <p>
          <span style="font-weight: bold;">作者：</span><a 
            target="_blank" 
            rel="nofollow noopener noreferrer" 
            href="/about">
            zwl5670
          </a>
        </p>
        <p>
          <span style="font-weight: bold;">文章链接：</span><a 
            target="_blank" 
            rel="nofollow noopener noreferrer" 
            href="https://zwl5670.gitee.io/2014/08/01/14-%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/05-%E9%A1%B5%E9%9D%A2%E6%B8%B2%E6%9F%93%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/">
            https://zwl5670.gitee.io/2014/08/01/14-%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/05-%E9%A1%B5%E9%9D%A2%E6%B8%B2%E6%9F%93%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/
          </a>
        </p>
        <p><span style="font-weight: bold;">版权声明：</span>本博客所有文章除特别声明外，均采用<a target="_blank" rel="noopener" href="https://creativecommons.org/licenses/by-nc-sa/4.0/deed.zh">CC BY-NC-SA 4.0 协议</a>。转载请注明出处！</p>
      </div>
    
  </div>
</article>
<div class="nav">
  
    <div class="nav-item-prev">
      <a 
        href="/2014/08/01/14-%E5%89%8D%E7%AB%AF%E6%80%A7%E8%83%BD%E4%BC%98%E5%8C%96/lazyload&amp;%E9%98%B2%E6%8A%96%E5%8A%A8%E5%92%8C%E8%8A%82%E6%B5%81%E9%98%80/" 
        class="nav-link">
        <i class="iconfont icon-left nav-prev-icon"></i>
        <div>
          <div class="nav-label">上一篇</div>
          
            <div class="nav-title">06-lazyload&amp;防抖动和节流阀 </div>
          
        </div>
      </a>
    </div>
  
  
    <div class="nav-item-next">
      <a 
        href="/2012/08/01/12-Vue%E5%9F%BA%E7%A1%80/01-Vue%E7%9A%84%E4%BB%8B%E7%BB%8D%E5%92%8Cvue-cli/" 
        class="nav-link">
        <div>
          <div class="nav-label">下一篇</div>
          
            <div class="nav-title">01-Vue的介绍和vue-cli </div>
          
        </div>
        <i class="iconfont icon-right nav-next-icon"></i>
      </a>
    </div>
  
</div>

<div 
  class="card card-content toc-card" 
  id="mobiletoc">
  <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8F%E8%A7%88%E5%99%A8%E6%B8%B2%E6%9F%93%E8%BF%87%E7%A8%8B"><span class="toc-text">浏览器渲染过程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E6%B8%B2%E6%9F%93%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88%E6%80%BB%E8%A7%88"><span class="toc-text">页面渲染技术方案总览</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E5%8C%96%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">静态化技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB%E6%8A%80%E6%9C%AF%E4%B8%8E%E5%AE%9E%E7%8E%B0"><span class="toc-text">前后端分离技术与实现</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8D%95%E9%A1%B5%E9%9D%A2%E5%BA%94%E7%94%A8%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">单页面应用技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#BigPipe-%E7%AE%80%E4%BB%8B%E5%92%8C%E5%B7%A5%E4%BD%9C%E6%A8%A1%E5%BC%8F"><span class="toc-text">BigPipe 简介和工作模式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%90%8C%E6%9E%84%E7%9B%B4%E5%87%BA%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">同构直出技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PWA-%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88%E5%92%8C%E5%AE%9E%E7%8E%B0%E6%80%9D%E8%B7%AF"><span class="toc-text">PWA 技术方案和实现思路</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E7%AD%96%E7%95%A5%E4%BC%98%E5%8C%96"><span class="toc-text">页面加载策略优化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%87%92%E5%8A%A0%E8%BD%BD"><span class="toc-text">懒加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A2%84%E5%8A%A0%E8%BD%BD"><span class="toc-text">预加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A2%84%E6%B8%B2%E6%9F%93"><span class="toc-text">预渲染</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8C%89%E9%9C%80%E5%8A%A0%E8%BD%BD"><span class="toc-text">按需加载</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3%E6%9C%8D%E5%8A%A1%E8%B0%83%E7%94%A8%E4%BC%98%E5%8C%96"><span class="toc-text">接口服务调用优化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3%E7%BC%93%E5%AD%98%E7%AD%96%E7%95%A5%E4%BC%98%E5%8C%96"><span class="toc-text">接口缓存策略优化</span></a></li></ol>
</div>
            </main>
            <aside class="right-column">
              <div class="sticky-widescreen">
  
  
    <article class="card card-content toc-card">
      <div class="toc-header">
  <i 
    class="iconfont icon-menu" 
    style="padding-right: 2px;">
  </i>目录
</div>
<ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%B5%8F%E8%A7%88%E5%99%A8%E6%B8%B2%E6%9F%93%E8%BF%87%E7%A8%8B"><span class="toc-text">浏览器渲染过程</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E6%B8%B2%E6%9F%93%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88%E6%80%BB%E8%A7%88"><span class="toc-text">页面渲染技术方案总览</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%9D%99%E6%80%81%E5%8C%96%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">静态化技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%89%8D%E5%90%8E%E7%AB%AF%E5%88%86%E7%A6%BB%E6%8A%80%E6%9C%AF%E4%B8%8E%E5%AE%9E%E7%8E%B0"><span class="toc-text">前后端分离技术与实现</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8D%95%E9%A1%B5%E9%9D%A2%E5%BA%94%E7%94%A8%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">单页面应用技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#BigPipe-%E7%AE%80%E4%BB%8B%E5%92%8C%E5%B7%A5%E4%BD%9C%E6%A8%A1%E5%BC%8F"><span class="toc-text">BigPipe 简介和工作模式</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%90%8C%E6%9E%84%E7%9B%B4%E5%87%BA%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88"><span class="toc-text">同构直出技术方案</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#PWA-%E6%8A%80%E6%9C%AF%E6%96%B9%E6%A1%88%E5%92%8C%E5%AE%9E%E7%8E%B0%E6%80%9D%E8%B7%AF"><span class="toc-text">PWA 技术方案和实现思路</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E5%8A%A0%E8%BD%BD%E7%AD%96%E7%95%A5%E4%BC%98%E5%8C%96"><span class="toc-text">页面加载策略优化</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%87%92%E5%8A%A0%E8%BD%BD"><span class="toc-text">懒加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A2%84%E5%8A%A0%E8%BD%BD"><span class="toc-text">预加载</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E9%A2%84%E6%B8%B2%E6%9F%93"><span class="toc-text">预渲染</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%8C%89%E9%9C%80%E5%8A%A0%E8%BD%BD"><span class="toc-text">按需加载</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3%E6%9C%8D%E5%8A%A1%E8%B0%83%E7%94%A8%E4%BC%98%E5%8C%96"><span class="toc-text">接口服务调用优化</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E6%8E%A5%E5%8F%A3%E7%BC%93%E5%AD%98%E7%AD%96%E7%95%A5%E4%BC%98%E5%8C%96"><span class="toc-text">接口缓存策略优化</span></a></li></ol>
    </article>
  
  
  <article class="card card-content">
    <div class="recent-posts-card">
  <div class="recent-posts-header">
    <i 
      class="iconfont icon-wenzhang_huaban" 
      style="padding-right: 2px;">
    </i>最近文章
  </div>
  <div class="recent-posts-list">
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2023-03-09</div>
        <a href="/2023/03/09/13-React%E5%9F%BA%E7%A1%80/11-React%20Navive%E5%88%9D%E8%AF%86/"><div class="recent-posts-item-content">11-React Navive初识</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2023-03-09</div>
        <a href="/2023/03/09/13-React%E5%9F%BA%E7%A1%80/10-AntD%E6%A1%86%E6%9E%B6%E7%9A%84upload%E7%BB%84%E4%BB%B6%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87%E6%97%B6%E4%BD%BF%E7%94%A8customRequest%E6%96%B9%E6%B3%95%E8%87%AA%E5%AE%9A%E4%B9%89%E4%B8%8A%E4%BC%A0%E8%A1%8C%E4%B8%BA/"><div class="recent-posts-item-content">10-AntD框架的upload组件上传图片时使用customRequest方法自定义上传行为</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2023-03-09</div>
        <a href="/2023/03/09/13-React%E5%9F%BA%E7%A1%80/09-AntD%E6%A1%86%E6%9E%B6%E7%9A%84upload%E7%BB%84%E4%BB%B6%E4%B8%8A%E4%BC%A0%E5%9B%BE%E7%89%87%E6%97%B6%E9%81%87%E5%88%B0%E7%9A%84%E4%B8%80%E4%BA%9B%E5%9D%91/"><div class="recent-posts-item-content">09-AntD框架的upload组件上传图片时遇到的一些坑</div></a>
      </div>
    
      <div class="recent-posts-item">
        <div class="recent-posts-item-title">2023-03-09</div>
        <a href="/2023/03/09/13-React%E5%9F%BA%E7%A1%80/08-Ant%20Design%E7%9A%84%E5%9F%BA%E6%9C%AC%E4%BD%BF%E7%94%A8/"><div class="recent-posts-item-content">08-Ant Design的基本使用</div></a>
      </div>
    
  </div>
</div>
  </article>
  
  
</div>
            </aside>
          </div>
        </div>
      </div>
    </div>
     
    <footer class="footer">
  <div class="footer-container">
    <div>
      <div class="footer-dsc">
        <span>
          Copyright ©
          
            2023
          
          
        </span>
        &nbsp;
        <a 
          href="/" 
          class="footer-link">
          前端面试
        </a>
      </div>
    </div>

    
      <div class="footer-dsc">
        
          Powered by
          <a 
            href="https://hexo.io/" 
            class="footer-link" 
            target="_blank" 
            rel="nofollow noopener noreferrer">
            &nbsp;Hexo
          </a>
        
        
          <span>&nbsp;|&nbsp;</span>
        
        
          Theme -
          <a 
            href="https://github.com/theme-kaze" 
            class="footer-link" 
            target="_blank"
            rel="nofollow noopener noreferrer">
            &nbsp;Kaze
          </a>
        
      </div>
    
    
    
    
</footer>
 
    
  <a 
    role="button" 
    id="scrollbutton" 
    class="basebutton" 
    aria-label="回到顶部">
    <i class="iconfont icon-arrowleft button-icon"></i>
  </a>

<a 
  role="button" 
  id="menubutton"
  aria-label="menu button"
  class="basebutton">
  <i class="iconfont icon-menu button-icon"></i>
</a>
<a 
  role="button" 
  id="popbutton" 
  class="basebutton" 
  aria-label="控制中心">
  <i class="iconfont icon-expand button-icon"></i>
</a>
<a 
  role="button" 
  id="darkbutton" 
  class="basebutton darkwidget" 
  aria-label="夜色模式">
  <i class="iconfont icon-weather button-icon"></i>
</a>
<a 
  role="button" 
  id="searchbutton" 
  class="basebutton searchwidget" 
  aria-label="搜索">
  <i class="iconfont icon-search button-icon"></i>
</a> 
     
     
     
      <script>
  var addImgLayout = function () {
    var img = document.querySelectorAll('.post-content img')
    var i
    for (i = 0; i < img.length; i++) {
      var wrapper = document.createElement('a')
      wrapper.setAttribute('href', img[i].getAttribute('data-src'))
      wrapper.setAttribute('aria-label', 'illustration')
      wrapper.style.cssText =
        'width: 100%; display: flex; justify-content: center;'
      if (img[i].alt) wrapper.dataset.caption = img[i].alt
      wrapper.dataset.nolink = true
      img[i].before(wrapper)
      wrapper.append(img[i])
      var divWrap = document.createElement('div')
      divWrap.classList.add('gallery')
      wrapper.before(divWrap)
      divWrap.append(wrapper)
    }
    baguetteBox.run('.gallery')
  }
</script>
<script>
  loadScript(
    "/js/lib/lightbox/baguetteBox.min.js",
    addImgLayout
  )
</script>
 
     
     
    <script src="/js/main.js"></script> 
     
    
      <script>
        var addLazyload = function () {
          var observer = lozad('.lozad', {
            load: function (el) {
              el.srcset = el.getAttribute('data-src')
            },
            loaded: function (el) {
              el.classList.add('loaded')
            },
          })
          observer.observe()
        }
      </script>
      <script>
        loadScript('/js/lib/lozad.min.js', addLazyload)
      </script>
    
    <script src="//instant.page/5.1.0" type="module"
      integrity="sha384-by67kQnR+pyfy8yWP4kPO12fHKRLHZPfEsiSXR8u2IKcTdxD805MGUXBzVPnkLHw"></script>
    
    
  </body>
</html>
